from django.db import models
from django.conf import settings
from main.models import TouristAttraction  # 导入景点模型

class Collect(models.Model):
    user = models.ForeignKey(
        settings.AUTH_USER_MODEL,
        on_delete=models.CASCADE,
        verbose_name='用户',
        related_name='collects'
    )
    attraction = models.ForeignKey(
        TouristAttraction,
        on_delete=models.CASCADE,
        verbose_name='景点',
        related_name='collects'
    )
    created_at = models.DateTimeField(auto_now_add=True, verbose_name='收藏时间')
    notes = models.TextField(blank=True, verbose_name='收藏备注')

    class Meta:
        verbose_name = '景点收藏'
        verbose_name_plural = '景点收藏'
        unique_together = ('user', 'attraction')  # 用户和景点组合唯一
        ordering = ['-created_at']
        db_table = 'collect_collect'

    def __str__(self):
        return f"{self.user.username} 收藏了 {self.attraction.name}"